package thn.glf.org.personalfinancial.objData;

import java.util.ArrayList;

import thn.glf.org.lib.SQLiteDB;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class Setting {
	public static String TableName="tblSetting";
	public static String Filed_SettingID="SettingID";
	public static String Filed_Day="Day";
	private int SettingID;
	private int Day;
	private Context mContext;
	public Context getmContext() {
		return mContext;
	}

	public void setmContext(Context mContext) {
		this.mContext = mContext;
	}

	public Setting() {

	}

	public int getSettingID() {
		return SettingID;
	}

	public void setSettingID(int settingID) {
		SettingID = settingID;
	}

	public int getDay() {
		return Day;
	}

	public void setDay(int day) {
		Day = day;
	}
	public ArrayList<Setting>getList(){
		SQLiteDB db=new SQLiteDB(mContext);
		ArrayList<Setting> datalist=new ArrayList<Setting>();
		db.open();
		Cursor mCursor=db.query(true, TableName, new String[]{Filed_SettingID,Filed_Day}, null, null, null, null, null, null);
		if(mCursor!=null&&mCursor.moveToFirst()){
			do{
				Setting obj=new Setting();
				obj.setSettingID(mCursor.getInt(mCursor.getColumnIndex(Filed_SettingID)));
				obj.setDay(mCursor.getInt(mCursor.getColumnIndex(Filed_Day)));
				datalist.add(obj);
			}while(mCursor.moveToNext());
		}
		db.close();
		return datalist;
	}
	public long Update(Setting obj){
		SQLiteDB db=new SQLiteDB(mContext);
		long flag=0;
		db.open();
		ContentValues values = new ContentValues();
		values.put(Filed_Day, obj.getDay());
		flag=db.Update(TableName, values, Filed_SettingID+"=?", new String[]{"1"});
		db.close();
		return flag;
	}
}
